<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Http\Middleware\BaseMiddleware;
use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;

class AdminAuthenticate extends BaseMiddleware{

    public function handle(Request $request, Closure $next, ...$guards)
    {

        try{
//            auth('admin')->logout();
//            $this->checkForToken($request);
            dump(1233);
//            if(auth('admin')->check()){
//
////            $roles = auth('admin')->user()->role;
////            dump($roles['rules']);
//            }
//            throw new UnauthorizedHttpException('jwt-auth', 'Token not provided');
            return redirect(route('admin.login'));
            return redirect()->route('admin.login');
            return $next($request);
        }catch (TokenExpiredException $e){
            throw new UnauthorizedHttpException('jwt-auth', $e->getMessage());
        }


    }


}
